﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using WindowsInput.Native;

namespace UniPie
{
	/// <summary>
	/// Defines the response in a Behavior, which response is invoked when
	/// the related TriggerState and the current state of the system matches.
	/// 
	/// Currently there are two (exclusive) response types:
	/// 
	/// - Input remapping: If UseRemapping is true then the TriggerState's 
	/// KeyboardMouseCombo, the 'hotkey' for the behavior is transparently
	/// remapped to a different key/mouse combo.
	/// For example middle mouse button could be converted into Space+LMB for
	/// simpler panning in Photoshop.
	/// 
	/// - Pie menu: A pie menu is shown while the 'hotkey' is held. Mouse hover
	/// selects pie slices. The pie menu goes away when the hotkey is released.
	/// If at that time the pie center was selected then the original (suppressed)
	/// hotkey is forwarded to the focused application. If a slice was selected
	/// then the slice's defined key/mouse combo is sent instead. If the mouse
	/// was off the pie menu when it disappeared then nothing is sent at all.
	/// </summary>
	public class Response
	{
		/// <summary>
		/// If true then the invoking key/mouse combo will be remapped to something else.
		/// </summary>
		public bool UseRemapping { get; set; }

		/// <summary>
		/// The key/mouse combo which should be sent instead of the suppressed invoke combo.
		/// </summary>
		public ObservableCollection<VirtualKeyCode> RemappedCombo { get; set; }

		/// <summary>
		/// Defines pie menu types (shapes). Currently unused.
		/// </summary>
		public int PieMenuType { get; set; }

		/// <summary>
		/// The list of slice definitions making up the pie menu.
		/// </summary>
		public ObservableCollection<SliceDefinition> SliceDefinitions { get; set; }

		public Response()
		{
			UseRemapping = true;
			RemappedCombo = new ObservableCollection<VirtualKeyCode>();
			PieMenuType = 0;
			SliceDefinitions = new ObservableCollection<SliceDefinition>();
		}

		/// <summary>
		/// Deep copy constructor.
		/// </summary>
		public Response(Response r)
		{
			UseRemapping = r.UseRemapping;
			RemappedCombo = new ObservableCollection<VirtualKeyCode>(r.RemappedCombo);
			PieMenuType = r.PieMenuType;

			SliceDefinitions = new ObservableCollection<SliceDefinition>();
			foreach (SliceDefinition sd in r.SliceDefinitions)
			{
				int i = 0;
				SliceDefinitions.Add(new SliceDefinition(r.SliceDefinitions[i]));
				i++;
			}
		}

		public Response(bool TheUseRemapping, ObservableCollection<VirtualKeyCode> TheRemappedCombo, int ThePieMenuType, ObservableCollection<SliceDefinition> TheSliceDefinitions)
		{
			UseRemapping = TheUseRemapping;
			RemappedCombo = TheRemappedCombo;
			PieMenuType = ThePieMenuType;
			SliceDefinitions = TheSliceDefinitions;
		}
	}
}
